<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>审批借货订单撤消请求（财务）</title>
    <script type="text/javascript">
      Ext.onReady(function(){
        var loanId = new Ext.form.Hidden({
          name: 'id'
        });

        //备注
        var desc = new Ext.form.TextField({
          fieldLabel: '备注',
          name: 'description',
          readOnly:true,
          anchor: '90%'
        });

        var toCustomer = new Ext.form.TextField({
          fieldLabel: '到客户',
          name: 'customer_name',
          readOnly:true,
          anchor: '90%'
        });

        //要求发货时间
        var actionDate = new Ext.form.DateField({
          fieldLabel: '发货日期',
          name: 'action_date',
          format: 'Y-m-d', //格式化日期
          readOnly:true,
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-18",
          allowBlank: true,
          blankText: "发货日期必须选择",
          emptyText: '发货日期...'
          //anchor: '50%'
        });
        //合同号
        var contractNumber = new Ext.form.TextField({
          fieldLabel: '合同编号',
          readOnly:true,
          name: 'contract_number',
          anchor: '90%'
        });

        //联系人
        var linkman = new Ext.form.TextField({
          fieldLabel: '联系人',
          name: 'linkman',
          readOnly:true
        });
        
        //联系电话
        var phone = new Ext.form.TextField({
          fieldLabel: '联系电话',
          name: 'phone',
          readOnly:true
        });

        var deliveryAddress = new Ext.form.TextField({
          fieldLabel: '送货地址',
          readOnly:true,
          name: 'delivery_address',
          anchor: '90%'
        });

        //--------------------------------------------------------------------------
        
        //借货订单列表Grid Store
        var loanDetailDS = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: '/loan/getLoanDetailsById'
          }),
          reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'product_name',
              mapping:'product.name'
            },{
              name: 'number',
              mapping: 'product.number'
            }, {
              name: 'spec',
              mapping:'product.spec'
            }, {
              name: 'unit',
              mapping:'product.unit'
            }, {
              name: 'description'
            }, {
              name: 'quantity',
              type: 'int'
            },{
              name: 'product_id'
            },{
              name: 'is_suit',
              mapping: 'product.is_suit',
              convert:function(value,record){
                if(value == "1"){
                  return "套装";
                }else if(value == "0"){
                  return "单品";
                }
              }
            }])
        });
        loanDetailDS.baseParams.loan_id = <%=params[:loan_id]%>;
        loanDetailDS.load();
        
        //生成产品Grid的CM
        var loanDetailSM = new Ext.grid.CheckboxSelectionModel({singleSelect:true});
        //var loanDetailSM = new Ext.grid.RowSelectionModel({singleSelect:true});
        var loanDetailCM = new Ext.grid.ColumnModel({defaults: {
            sortable: true,
            menuDisabled: false
          },columns:[new Ext.grid.RowNumberer(),loanDetailSM,{
              header: '产品名称',
              dataIndex: 'product_name',
              width: 230
            },{
              header: '产品ID',
              dataIndex: 'product_id',
              width: 50,
              hidden: false
            },{
              header: '产品编号',
              dataIndex: 'number',
              width: 90
            },{
              header: '规格',
              dataIndex: 'spec',
              width: 50
            },{
              header: '单位',
              dataIndex: 'unit',
              width: 50
            },{
              header: '数量',
              dataIndex: 'quantity',
              align: 'right',
              width: 50
            },{
              header: '套装或单品',
              dataIndex: 'is_suit',
              width: 70
            },{
              header: '备注',
              dataIndex: 'description',
              width: 60
            }
          ]});

        //生成要订单的产品的Grid
        var loanDetailGrid = new Ext.grid.EditorGridPanel({
          store: loanDetailDS,
          cm: loanDetailCM,
          sm: loanDetailSM,
          width: 850,
          height: 280,
          clicksToEdit: 1//这里应该是单击就可以修改的意思。因为默认是要双击的。          
        });

        //审批部分
        var auditingStatus = new Ext.form.RadioGroup({
          width : 120,
          fieldLabel: '是否通过',
          allowBlank: false,
          //hideLabel:true,
          //style:'margin-left:100px;margin-top:20px',
          //columns : 7,
          anchor: '30%',
          vertical :false,
          items:[
            {boxLabel:'是',inputValue:'是',name:'auditing_status'},
            {boxLabel:'否',inputValue:'否',name:'auditing_status'}
          ]
        });

        var auditOpinion = new Ext.form.TextArea({
          fieldLabel: '审批意见',
          name: 'audit_opinion',
          allowBlank: false,
          height: 40,
          width:680
        });
        
        //暂时保存按钮
        var submitButton = new Ext.Button({
          text: '审批并保存',
          tooltip: '保存借货订单。',
          iconCls: 'icon-save',
          handler: function(){
            if (loanFormPanel.form.isValid()) {
              this.disable();
              loanFormPanel.form.submit({
                method: 'GET',
                success: function(result, response){
                  if (response.result.info == "成功") {
                    //添加成功后，隐藏窗口，并刷新Grid
                    loanAuditForCancelWin.destroy();
                  }
                  else {
                    Ext.MessageBox.alert('提示', result.responseText);
                    loanAuditForCancelWin.destroy();
                  }
                },
                failure: function(result, response){
                  Ext.MessageBox.alert('提示', result.responseText);
                }
              });
            }
            else {
              Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
            }
          }
        });

        //暂时保存按钮
        var closeButton = new Ext.Button({
          text: '关闭',
          tooltip: '关闭当前窗口，并且当前编辑的信息不能保存。',
          iconCls: 'exit',
          handler: function(){
            loanAuditForCancelWin.destroy();
          }
        });
        
        //采购申请的FormPanel
        var loanFormPanel = new Ext.form.FormPanel({
          labelWidth: 55,
          width: '850',
          labelAlign: 'right',
          frame : true,
          url: '/loan/updateAuditingCancelStatus',
          method: 'GET',
          reader: new Ext.data.JsonReader({
            root: 'root'
          }, [{
              name: 'id'
            }, {
              name: 'customer_name',
              mapping: 'customer.name'
            }, {
              name: 'customer_id'
            }, {
              name: 'description'
            }, {
              name: 'action_date',
              type: 'date',
              dateFormat: 'Y/m/d'
            }, {
              name: 'contract_number'
            }, {
              name: 'linkman'
            }, {
              name: 'phone'
            }, {
              name: 'tax_rate'
            }, {
              name: 'delivery_address'
            },{
              name: 'audit_opinion'
            }]),
          //defaultType: 'textfield',
          items: [{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .4,
                  layout: 'form',
                  border: false,
                  items: [toCustomer]
                }, {
                  columnWidth: .3,
                  layout: 'form',
                  border: false,
                  items: [actionDate]
                }, {
                  columnWidth: .3,
                  layout: 'form',
                  border: false,
                  items: [contractNumber]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .4,
                  layout: 'form',
                  border: false,
                  items: [linkman]
                }, {
                  columnWidth: .3,
                  layout: 'form',
                  border: false,
                  items: [phone]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: 1,
                  layout: 'form',
                  border: false,
                  items: [deliveryAddress]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: 1,
                  layout: 'form',
                  border: false,
                  items: [desc]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: 1,
                  layout: 'form',
                  border: false,
                  items: [loanDetailGrid]
                }]
            },loanId,{
              xtype: 'fieldset',
              //defaults: {width: 700},
              title: '审批(撤消)',
              border: true,
              items: [auditingStatus,auditOpinion]
            }],
          buttons: [submitButton,closeButton]
        });

        loanFormPanel.form.load({
          url: '/loan/getLoanById?id=' + <%=params[:loan_id]%>,
          method : 'GET',
          waitMsg: '正在载入数据...',
          success: function(form, action){
          },
          failure: function(form, action){
            Ext.MessageBox.alert('提示信息', '信息加载失败');
          }
        });        
        loanFormPanel.render('audit_loan_for_cancel_form');

      })
    </script>
  </head>
  <body>
    <div id="audit_loan_for_cancel_form"></div>
  </body>
</html>